/* SVN Info:
 * $HeadURL: http://jkad.googlecode.com/svn/trunk/JKad/src/jkad/controller/ThreadGroupLocal.java $
 * $LastChangedRevision: 24 $
 * $LastChangedBy: polaco $                             
 * $LastChangedDate: 2006-09-04 05:32:35 +0000 (Mon, 04 Sep 2006) $  
 */
package jkad.controller;

import java.util.HashMap;

public abstract class ThreadGroupLocal<T>
{
    private HashMap<ThreadGroup, T> map;

    public ThreadGroupLocal()
    {
        map = new HashMap<ThreadGroup, T>();
    }

    public T get()
    {
        T result = null;
        ThreadGroup group = Thread.currentThread().getThreadGroup();
        synchronized (map)
        {
            result = map.get(group);
            if (result == null)
            {
                result = initialValue();
                map.put(group, result);
            }
        }
        return result;
    }

    public void set(T obj)
    {
        map.put(Thread.currentThread().getThreadGroup(), obj);
    }

    public abstract T initialValue();
}
